package odgs.app;

import odgs.app.client.ClientMainFrameController;
import odgs.app.client.ClientMainFrameUI;
import odgs.manager.DataManager;
import odgs.manager.ExecuteManager;
import odgs.manager.NetworkManager;
import odgs.manager.ResourceManager;
import odgs.manager.TransactionManager;
import odgs.message.ClientMessageProcessor;

public class GridClient2 
{
	private DataManager dataManager;
	private ExecuteManager	executeManager;
	private String fileName = "data/node2.dat";
	private String ip = "127.0.0.1";
	private NetworkManager	networkManager;
	private int port = 7777;
	private ClientMessageProcessor processor;
	private ResourceManager	resourceManager;
	private TransactionManager	transactionManager;
	
	public GridClient2()
	{
		init();
	}

	public GridClient2(String ip, String port) 
	{
		this.ip = ip;
		this.port = Integer.parseInt(port);
		init();
	}

	private void init() 
	{
		networkManager = new NetworkManager();
		resourceManager = new ResourceManager();
		dataManager = new DataManager();
		executeManager = new ExecuteManager();
		transactionManager = new TransactionManager();
		
		networkManager.setResourceManager(resourceManager);
		executeManager.setTransactionManager(transactionManager);
		
		dataManager.setNetworkManager(networkManager);
		transactionManager.setNetworkManager(networkManager);
		transactionManager.setResouceManager(resourceManager);
		
		processor = new ClientMessageProcessor();
		processor.setNetworkManager(networkManager);
		processor.setDataManager(dataManager);
		processor.setTransactionManager(transactionManager);
		processor.setExecuteManager(executeManager);
		processor.setResourceManager(resourceManager);
		
		ClientMainFrameUI ui = new ClientMainFrameUI();
		ClientMainFrameController controller = new ClientMainFrameController(ui);
		controller.setFileName(fileName);
		controller.setDataManager(dataManager);
		controller.setTransactionManager(transactionManager);
		controller.setExecuteManager(executeManager);
		
		dataManager.connectServer(ip, port);
	}
}
